package com.wangzhen.spring.i18n;

import java.text.MessageFormat;
import java.util.Date;

/**
 * Java原始MessageFormat演示示例
 */
public class MessageFormatTest {

    public static void main(String[] args) {
        // MessageFormat 演示示例1
        int planet = 7;
        String event = "a disturbance in the Force";

        String result = MessageFormat.format(
                "At {1,time,full} on {1,date,full}, there was {2} on planet {0,number,integer}.",
                planet, new Date(), event);
        System.out.println(result);

        // MessageFormat 演示示例2
        MessageFormat mf =
                new MessageFormat("At {1,time,full} on {1,date,full}, there was {2} on planet {0,number,integer}.");
        result = mf.format(new Object[]{planet, new Date(), event});
        System.out.println(result);

        // 重置MessageFormat 的模式,把之前定义的messageFormat给修改掉了
        mf.applyPattern("Welcome {0} to Country {1}");
        result = mf.format(new Object[]{"zhangsan", "china"});
        System.out.println(result);



    }
}
